<script setup>
import {getCurrentInstance, ref} from 'vue'
import {
  ElRow,
  ElCol,
  ElCard,
  ElIcon,
} from 'element-plus'
const homepageList = ref([])
const instance = getCurrentInstance();
if (instance) {
  const global = instance.appContext.config.globalProperties;
  global.$http.get('/public/homepage/queryall')
      .then(resp => {
        console.log(resp.data);
        homepageList.value = resp.data;
      })
      .catch(err => {
        console.error(new Error(err));
      });
}
const load = () => {
  count.value += 2
}
// 标签背景色（可动态配置）
/*const tagBg = 'linear-gradient(90deg, #ff6b6b, #4ecdc4)'*/

// 点赞功能
/*const toggleLike = (item) => {
  item.hasLiked = !item.hasLiked
  item.hasLiked ? item.likes++ : item.likes--
}*/
</script>

<template>
  <div class="recommend-container">
    <!-- 标题栏（可根据需求扩展） -->
    <div class="title-bar">
      <h2>精彩推荐</h2>
    </div>

    <!-- 内容列表 -->
    <el-row v-infinite-scroll="load" :gutter="24">
      <el-col
          v-for="homepage in homepageList.filter(item => item.id<29)"
          :key="homepage.id"
          :span="12"
      >
        <el-card class="recommend-card">
          <!-- 封面图 -->
          <img
              v-if="homepage.url"
              :src="homepage.url"
              alt="cover"
              class="cover"
          >


          <!-- 内容区域 -->
          <div class="content">
            <!-- 标题/名字 -->
            <div class="title">{{ homepage.name }}</div>

            <!-- 副标题/描述 -->
            <div class="subtitle">{{ homepage.desc }}</div>


          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>



<style scoped>
.recommend-container {
  padding: 20px;
}

.title-bar {
  margin-bottom: 20px;
}

/* 响应式布局 */
.recommend-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  transition: all 0.3s;
}

.recommend-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* 封面图 */
.cover {
  width: 100%;
  border-radius: 8px;
}

/* 视频标记 */
/*.video-tag {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 6px 12px;
  border-radius: 4px;
}*/

/*.play-icon {
  font-size: 20px;
}*/

/* 内容区域 */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px;
}

.title {
  font-size: 16px;
  font-weight: 500;
  margin: 8px 0;
  line-height: 1.4;
  overflow: hidden;       /* 内容溢出的部分隐藏,和下面两个样式一起使用才生效 */
  white-space: nowrap;    /* 内容不换行 */
  text-overflow: ellipsis; /* 当对象内文本溢出时显示省略标记（...）*/

}

.subtitle {
  font-size: 14px;
  color: #666;
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 元信息 */
/*.meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}*/

/*.category {
  padding: 4px 8px;
  border-radius: 4px;
  color: #fff;
  font-size: 12px;
}*/

/*.like {
  cursor: pointer;
  color: #666;
  display: flex;
  align-items: center;
}*/

.like el-icon {
  margin-right: 4px;
}

/*.like:hover {
  color: #ff6b6b;
}*/
</style>
